package question.solution690;
import	java.util.HashMap;

import question.SolutionTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Solution690 implements SolutionTemplate {

    class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }

    public int getImportance(List<Employee> employees, int id) {
        Map<Integer, Employee> idEmployeeMap = getIdEmployeeMap(employees);
        return getImportance(idEmployeeMap, id);
    }

    private int getImportance(Map<Integer, Employee> idEmployeeMap, int id){
        Employee employee = idEmployeeMap.get(id);
        int importance = employee.importance;
        for(Integer employeeId : employee.subordinates){
            importance += getImportance(idEmployeeMap, employeeId);
        }
        return importance;
    }
    private Map<Integer, Employee> getIdEmployeeMap(List<Employee> employees){
        Map<Integer, Employee> result = new HashMap<Integer, Employee> ();

        for(Employee employee : employees){
            result.put(employee.id, employee);
        }
        return result;
    }

    @Override
    public void test() {
//        int[][] matrix = new int[1][1];
//        int[] arr = {1};
//        matrix[0] = arr;
//        List<Integer> result = spiralOrder(matrix);
        System.out.println();
        return;
    }
}
